<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="110px"
    >
      <el-form-item label="车牌号:" prop="carNumber">
        <el-input
          v-model="queryParams.carNumber"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="司机电话:" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入司机电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审单人:" prop="checkPerson">
        <el-input
          v-model="queryParams.checkPerson"
          placeholder="请输入审单人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约状态:" prop="reservationStatus">
        <el-select
          v-model="queryParams.reservationStatus"
          placeholder="请选择预约状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.reservation_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="签到日期:" prop="takeDate">
        <el-date-picker
          clearable
          v-model="queryParams.takeDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择收货完成日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="reservationList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="仓库类型" align="center" prop="warehouse">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.warehouse"
            :value="scope.row.warehouse"
          />
        </template>
      </el-table-column>
      <el-table-column label="司机姓名" align="center" prop="driverName" />
      <el-table-column label="司机手机号" align="center" prop="phone" />
      <el-table-column label="车牌号" align="center" prop="carNumber" />
      <el-table-column label="预约送货日期" align="center" prop="sendDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sendDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="时间段" align="center" prop="timeSlot">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.time_slot"
            :value="scope.row.timeSlot"
          />
        </template>
      </el-table-column>
      <el-table-column label="送货渠道" align="center" prop="sendChannel">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.send_channel"
            :value="scope.row.sendChannel"
          />
        </template>
      </el-table-column>
      <el-table-column label="货物类型" align="center" prop="goodsType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.goods_type"
            :value="scope.row.goodsType"
          />
        </template>
      </el-table-column>
      <el-table-column label="送货件数" align="center" prop="sendCount" />
      <el-table-column label="预约申请日期" align="center" prop="checkDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预约状态" align="center" prop="reservationStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.reservation_status"
            :value="scope.row.reservationStatus"
          />
        </template>
      </el-table-column>
      <el-table-column label="签到时间" align="center" prop="takeDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.takeDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:reservation:edit']"
            >呼叫</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:reservation:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改预约管理对话框 -->
  </div>
</template>

<script>
import {
  listReservation,
  getReservation,
  delReservation,
  addReservation,
  updateReservation,
} from "@/api/system/reservation";

export default {
  name: "Reservation",
  dicts: [
    "reservation_status",
    "time_slot",
    "send_channel",
    "goods_type",
    "warehouse",
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预约管理表格数据
      reservationList: [
        {
          id: "1",
          warehouse: "0",
          driverName: "李一鸣",
          phone: "15236703045",
          carNumber: "陕AAU2345",
          sendDate: "2023-09-21",
          timeSlot: "1",
          sendChannel: "0",
          goodsType: "1",
          sendCount: "1000",
          checkDate: "2023-09-21",
          reservationStatus: "1",
          takeDate: "2023-09-21",
          remark: "111",
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNumber: null,
        phone: null,
        checkPerson: null,
        takeDate: new Date().toISOString().split("T")[0],
        reservationStatus: "1",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预约管理列表 */
    getList() {
      // this.loading = true;
      // listReservation(this.queryParams).then((response) => {
      //   this.reservationList = response.rows;
      //   this.total = response.total;
      //   this.loading = false;
      // });
      this.loading = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        carNumber: null,
        phone: null,
        checkPerson: null,
        takeDate: null,
        reservationStatus: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids;
    //   getReservation(id).then((response) => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改预约管理";
    //   });
    // },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateReservation(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReservation(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  },
};
</script>
<style scoped>
.el-select {
  width: 220px;
}
.el-input--small {
  width: 220px;
}
</style>
